
###Clear R--------------------
rm(list=ls())

###Load data-----------
load("Study1_data.RData")

###Function to recode variables to range from lowest (0) to highest (1) observation---------------------
zero1 <- function(x, minx=NA, maxx=NA){
  res <- NA
  if(is.na(minx)) res <- (x - min(x,na.rm=T))/(max(x,na.rm=T) -min(x,na.rm=T))
  if(!is.na(minx)) res <- (x - minx)/(maxx -minx)
  res
}

####function to install packages if they don't exist----------------
ipak <- function(pkg){
  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  if (length(new.pkg)) 
    install.packages(new.pkg, dependencies = TRUE)
  sapply(pkg, require, character.only = TRUE)
}
# usage
packages <- c("ggplot2", "psych","interplot","stargazer","dplyr","stringr","tidyr", "xtable", "Hmisc")
ipak(packages)

### Appendix A.1: Sample characteristics---------------------

#democrats
table(data$Republican_dummy) #self-identified republicans
table(data$pid1) #2==Democrat
table(data$pid4) #2==Democrat
384+83 #self-identified Democrat

#Female
table(data$female)

prop.table(table(data$female))

#Race
table(data$race)
prop.table(table(data$race==1))[2] #white
prop.table(table(data$race==2))[2] #black

#Hispanic
prop.table(table(data$hispanic))

#Age
median(data$age)
min(data$age)
max(data$age)

#education
prop.table(table(data$education))
349/(268+349+130)

### Appendix A.3: Partisan Social Identity Strength---------------------

#Partisan Social Identity Strength
summary(data$partyidentity)
sd(data$partyidentity, na.rm=T)
skewness(data$partyidentity, na.rm=T)
kurtosis(data$partyidentity, na.rm=T)
psych::alpha(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(huddy1, huddy2, huddy3, huddy4, huddy5, huddy6, huddy7, huddy8))),check.keys = T)
psych::omega(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(huddy1, huddy2, huddy3, huddy4, huddy5, huddy6, huddy7, huddy8))),check.keys = T)

huddy_latent<-'pid =~ NA*huddy1 +huddy2+huddy3+huddy4+huddy5+huddy6+huddy7+huddy8 
                # fix variance of latent variable
                pid ~~ 1*pid'
fit <- cfa(huddy_latent, ordered = c("huddy1", "huddy2", "huddy3", "huddy4", "huddy5", "huddy6", "huddy7", "huddy8"),data=data)
parameterEstimates(fit, standardized=TRUE)
p<-parameterEstimates(fit, standardized=TRUE) %>%  dplyr::select(std.all, pvalue)
p <- p[-c(9:66), ] 
names(p) <- c("Standardized Factor Loading", "p-value")
p<-xtable(caption = "Partisan Social Identity Strength: Standardized Factor Loadings", label = "tab:cfaPID2", p)
print(p, file="Study1_PID_cfa.tex", type="latex", caption.placement="top")

#Histogram of PID strenght
ggplot(data, aes(x = partyidentity)) + geom_histogram(binwidth = 0.01)+theme_bw()+labs(x="Partisan Social Identity Strength", y="Count")
ggsave("Study1_PID_distribution.pdf",width=8,height=4)

### Appendix A.4: Cognitive resources: CRT --------------------
summary(data$CRTall)
sd(data$CRTall)
skewness(data$CRTall)
kurtosis(data$CRTall)

psych::alpha(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(CRT1, CRT2,CRT3))),check.keys = T)
psych::omega(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(CRT1, CRT2,CRT3))),check.keys = T)


#Tetrachoric correlations
data_crt<-data.frame(data$CRT1,  data$CRT2, data$CRT3)
poly_values = polychoric(data_crt)
items_polychoric = poly_values$rho 
items_polychoric[lower.tri(items_polychoric)] <- NA #remove lower part of the triangle
p<-xtable(caption = "CRT: Tetrachoric Correlations", label = "tab:corCRT1", items_polychoric)
names(p) <- c("CRT1", "CRT2", "CRT3")
rownames(p) <- c("CRT1", "CRT2", "CRT3")
print(p, file="Study1_CRT.tex", type="latex", caption.placement="top")

#Histogram of CRT
ggplot(data, aes(x = zero1(CRTall))) + geom_histogram(binwidth = 0.01)+theme_bw()+labs(x="Cognitive Reflection Test", y="Count")
#save results
ggsave("Study1_CRT_distribution.pdf",width=8,height=4)


### Appendix A.4: Cognitive resources: NfC--------------------------------

summary(data$nfc)
sd(data$nfc)
skewness(data$nfc, na.rm=T)
kurtosis(data$nfc, na.rm=T)
#alpha
psych::alpha(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(NfC_1,NfC_2,NfC_3,NfC_4,NfC_5,NfC_6,NfC_7,NfC_8,NfC_9,NfC_10,NfC_11,NfC_12,NfC_13,NfC_14,NfC_15,NfC_16,NfC_17,NfC_18))),check.keys = T)
#omega
psych::omega(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(NfC_1,NfC_2,NfC_3,NfC_4,NfC_5,NfC_6,NfC_7,NfC_8,NfC_9,NfC_10,NfC_11,NfC_12,NfC_13,NfC_14,NfC_15,NfC_16,NfC_17,NfC_18))),check.keys = T)

#creat factor analysis
data$NfC_3_rec <-  1-data$NfC_3
data$NfC_4_rec <-  1-data$NfC_4
data$NfC_5_rec <-  1-data$NfC_5
data$NfC_7_rec <-  1-data$NfC_7
data$NfC_8_rec <-  1-data$NfC_8
data$NfC_9_rec <-  1-data$NfC_9
data$NfC_12_rec <-  1-data$NfC_12
data$NfC_16_rec <-  1-data$NfC_16
data$NfC_17_rec <-  1-data$NfC_17

nfc_latent<-'nfc =~ NA*NfC_1 + NfC_2 + NfC_3_rec + NfC_4_rec + NfC_5_rec + NfC_6+ NfC_7_rec+NfC_8_rec+NfC_9_rec+NfC_10+NfC_11+NfC_12_rec+NfC_13+NfC_14+NfC_15+NfC_16_rec+NfC_17_rec+NfC_18
nfc ~~ 1*nfc'
fit <- cfa(nfc_latent, ordered = c("NfC_1", "NfC_2", "NfC_3_rec", "NfC_4_rec", "NfC_5_rec", "NfC_6", "NfC_7_rec", "NfC_8_rec", "NfC_9_rec", "NfC_10", "NfC_11", "NfC_12_rec", "NfC_13", "NfC_14", "NfC_15", "NfC_16_rec", "NfC_17_rec", "NfC_18"), data=data)
p<-parameterEstimates(fit, standardized=TRUE) %>%  dplyr::select(std.all, pvalue)
p <- p[-c(19:146), ] 
p<-xtable(caption = "Need for Cognition: Standardized Factor Loadings", label = "tab:cfaNFC2", p)
names(p) <- c("Standardized Factor Loading", "p-value")
print(p, file="Study1_NfC_cfa.tex", type="latex", caption.placement="top")

#Histogram of Need for Cognition
ggplot(data, aes(x = nfc)) + geom_histogram(binwidth = 0.01)+theme_bw()+labs(x="Need for Cognition", y="Count")
#save results
ggsave("Study1_NFC_distribution.pdf",width=8,height=6)

### Appendix A.4: Cognitive resources: Latent variable ----------------------

#Descriptives of Need for Cognition
summary(data$cogresources)
sd(data$cogresources)
skewness(data$cogresources)
kurtosis(data$cogresources)
#alpha
psych::alpha(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(CRT1, CRT2, CRT3, NfC_1,NfC_2,NfC_3,NfC_4,NfC_5,NfC_6,NfC_7,NfC_8,NfC_9,NfC_10,NfC_11,NfC_12,NfC_13,NfC_14,NfC_15,NfC_16,NfC_17,NfC_18))),check.keys = T)
#omega
psych::omega(mapply(function(x)zero1(as.numeric(x)),with(data,data.frame(CRT1, CRT2, CRT3,NfC_1,NfC_2,NfC_3,NfC_4,NfC_5,NfC_6,NfC_7,NfC_8,NfC_9,NfC_10,NfC_11,NfC_12,NfC_13,NfC_14,NfC_15,NfC_16,NfC_17,NfC_18))),check.keys = T)

latent <- ' cogresources  =~ NA*CRT1+CRT2+CRT3+NfC_1 + NfC_2 + NfC_3_rec + NfC_4_rec + NfC_5_rec + NfC_6+ NfC_7_rec+NfC_8_rec+NfC_9_rec+NfC_10+NfC_11+NfC_12_rec+NfC_13+NfC_14+NfC_15+NfC_16_rec+NfC_17_rec+NfC_18
# fix variance of latent variable
cogresources ~~ 1*cogresources'

fit <- cfa(latent, ordered=c("CRT1", "CRT2", "CRT3", "NFC_1", "NFC_2", "NFC_3_rec", "NFC_4_rec", "NFC_5_rec", "NfC_6", "NFC_7_rec", "NfC_8_rec", "NfC_9_rec", "NFC_10", "NFC_11", "NFC_12_rec", "NFC_13", "NfC_14", "NfC_15", "NfC_16_rec", "NfC_17_rec", "NfC_18"), data=data)

p<-parameterEstimates(fit, standardized=TRUE) %>%  dplyr::select(std.all, pvalue)
p <- p[-c(22:111), ] 
p["battery"]<-"NfC"
p[1:3,3]<-"CRT"
p<-xtable(caption = "Cognitive resources: Standardized Factor Loadings", label = "tab:cfacog1", p)
names(p) <- c("Standardized Factor Loading", "p-value", "Battery")
print(p, type="latex", file="Study1_cog_cfa.tex", caption.placement="top")

#Histogram 
ggplot(data, aes(x = zero1(cogresources))) + geom_histogram(binwidth = 0.01)+theme_bw()+labs(x="Cognitive resources", y="Count")
#save results
ggsave("Study1_cog_distribution.pdf",width=8,height=6)



### Appendix A.5: Randomization checks---------------------
#Table A.5 Balance checks: moderators
balance_crt<-lm(CRTall~as.factor(data$Treatment), data=data)
balance_nfc<-lm(nfc~as.factor(data$Treatment), data=data)
balance_cog<-lm(zero1(cogresources)~as.factor(data$Treatment), data=data)
balance_pid<-lm(partyidentity~as.factor(data$Treatment), data=data)

stargazer(balance_crt, balance_nfc, balance_cog, balance_pid, title="Balance checks: moderators", align=TRUE, 
          covariate.labels=c("Democrats support", "Republicans support"), 
          omit.stat=c("LL","ser","f", "adj.rsq"), 
          star.cutoffs=c(0.05), 
          notes.append = FALSE, 
          notes = "*p<0.05", 
          no.space=TRUE,out = "Study1_Balance.tex",dep.var.labels =c("CRT", "NfC", "Cog resources", "Partisan Social Identity Strength"),label="tab:Study2balance", digits=2)

#Table A.6 Party cues: Balance checks moderators per treatment condition
balance_crt1<-lm(CRTall~as.factor(data$InParty)+ as.factor(data$OutParty), data=data)
balance_nfc1<-lm(nfc~as.factor(data$InParty)+ as.factor(data$OutParty), data=data)
balance_cog1<-lm(zero1(cogresources)~as.factor(data$InParty)+ as.factor(data$OutParty), data=data)
balance_pid1<-lm(partyidentity~as.factor(data$InParty)+ as.factor(data$OutParty), data=data)

stargazer(balance_crt1, balance_nfc1,balance_cog1, balance_pid1, title="Party cues: Balance checks moderators per treatment condition", align=TRUE, 
          covariate.labels=c("In-party cue", "Out-party cue"), 
          omit.stat=c("LL","ser","f", "adj.rsq"), 
          star.cutoffs=c(0.05), 
          notes.append = FALSE, 
          notes = "*p<0.05", 
          no.space=TRUE,out = "Study1_Balance2.tex",dep.var.labels =c("CRT", "NfC", "Cog resources","Party Identity Strength"),label="tab:Study2_balance", digits=2)

#Table A7 Balance Checks Demographics
balanceSex<-glm(data$female~as.factor(data$Treatment), data=data, family=binomial(link="logit"))
balanceAge<-lm(data$age~as.factor(data$Treatment),data=data)
balanceEdu<-polr(as.factor(data$education)~as.factor(data$Treatment), data=data, Hess=TRUE)
balanceIncome<-lm(data$income~as.factor(data$Treatment),data=data)
balance_partisan<-glm(Republican_dummy~as.factor(data$Treatment), data=data, family=binomial(link="logit"))

stargazer(balanceSex, balanceAge, balanceEdu, balanceIncome, balance_partisan, title="Balance Checks Demographics", align=TRUE, 
          dep.var.labels=c("Sex", "Age", "Education", "Income", "Partisanship"), 
          covariate.labels=c("Democratic party supports", "Republican party supports"), 
          omit.stat=c("LL","ser","f", "adj.rsq"), 
          star.cutoffs=c(0.05), 
          notes = "*p<0.05", 
          notes.append = FALSE, 
          no.space=TRUE,out = "Study1_BalanceDem.tex", label="tab:balanceDemstudy1", digits=2)

#Table A.8 In-party vs. Out-party: Balance Checks Demographics
balanceSex1<-glm(data$female~as.factor(data$InParty)+ as.factor(data$OutParty), data=data, family=binomial(link="logit"))
balanceAge1<-lm(data$age~as.factor(data$InParty)+ as.factor(data$OutParty),data=data)
balanceEdu1<-polr(as.factor(data$education)~as.factor(data$InParty)+ as.factor(data$OutParty), data=data, Hess=TRUE)
balanceIncome1<-lm(data$income~as.factor(data$InParty)+ as.factor(data$OutParty),data=data)
balance_partisan1<-glm(Republican_dummy~as.factor(data$InParty)+ as.factor(data$OutParty), data=data, family=binomial(link="logit"))

stargazer(balanceSex1, balanceAge1, balanceEdu1, balanceIncome1, balance_partisan1, title="In-party vs. Out-party: Balance Checks Demographics", align=TRUE, 
          dep.var.labels=c("Sex", "Age", "Education", "Income", "Partisanship"), 
          covariate.labels=c("In-party cue", "Out-party cue"), 
          omit.stat=c("LL","ser","f", "adj.rsq"), 
          star.cutoffs=c(0.05), 
          notes = "*p<0.05", 
          notes.append = FALSE, 
          no.space=TRUE,out = "Study1_BalanceDem2.tex", label="tab:balanceDemIn", digits=2)



### Appendix A.6: Main effects----------------------
main<-(lm(DV_irradiation~InParty+OutParty+partyidentity+CRTall+age+female+non_white+as.factor(education)+Republican_dummy,data))
main1<-(lm(DV_irradiation~InParty+OutParty+partyidentity+nfc+age+female+non_white+as.factor(education)+Republican_dummy,data))
main2<-(lm(DV_irradiation~InParty+OutParty+partyidentity+cogresources+age+female+non_white+as.factor(education)+Republican_dummy,data))

stargazer(main, main1, main2, title="Main Effect of Party Cues on Support for Food Irradiation", align=TRUE, 
          covariate.labels=c("In-Party cue", "Out-Party cue", "PID Strength","CRT", "NfC", "Cognitive resources", "Age", "Female", "Race: non-white", "Education: Some college", "Education: College", "Party: Republican"), 
          omit.stat=c("LL","ser","f", "adj.rsq"), 
          notes.append = FALSE, 
          star.cutoffs=c(0.05), 
          notes = "*p<0.05", 
          no.space=TRUE,out = "Foodmain.tex",dep.var.caption = "Policy support",dep.var.labels.include = F,label="tab:foodmain", digits=2)

### Appendix A.7: Direct replication of Kam (2005)----------------------------
#Code treatment following Kam (2005)
#Party Cue: 1 (strong or weak partisan, out-party endorses ban); 0.5 (leaning partisan, out- party endorses ban); 0 (no party cue); +0.5 (leaning partisan, in-party endorses ban); +1 (strong or weak partisan, in-party endorses ban).
data$PartyCue<-NA
data$PartyCue[data$pid1==1 & data$Treatment==2]<--1
data$PartyCue[data$pid1==2 & data$Treatment==3]<--1
data$PartyCue[data$pid4==1 & data$Treatment==2]<--0.5
data$PartyCue[data$pid4==2 & data$Treatment==3]<--0.5
data$PartyCue[data$Treatment==1 & data$pid1==1]<--0
data$PartyCue[data$Treatment==1 & data$pid1==2]<--0
data$PartyCue[data$Treatment==1 & data$pid4==1]<--0
data$PartyCue[data$Treatment==1 & data$pid4==2]<--0
data$PartyCue[data$Treatment==3 & data$pid4==1]<-0.5
data$PartyCue[data$Treatment==2 & data$pid4==2]<-0.5
data$PartyCue[data$Treatment==3 & data$pid1==1]<-1
data$PartyCue[data$Treatment==2 & data$pid1==2]<-1

#recode variable to range from 0 - 1
data$SupportIrradiation_Kam<-((data$SupportIrradiation_rec-1)/4)
mean(data$SupportIrradiation_Kam)
sd(data$SupportIrradiation_Kam)

#Run models
summary(NFC18_kam<-(lm(data$SupportIrradiation_Kam~PartyCue*nfc,data=data)))
summary(NFC18<-(lm(data$DV_irradiation~PartyCue*nfc,data=data)))

#Create Table A.10
stargazer(NFC18_kam, NFC18, title="Moderation of Party Cues Following Kam (2005)", align=TRUE, 
          dep.var.labels=c("Support for Ban of Food Irradiation"), 
          covariate.labels=c("Party Cue", "NfC", "Party Cue * NfC"), 
          omit.stat=c("LL","ser","f", "adj.rsq"), 
          star.cutoffs=c(0.05), 
          notes = "OLS Regession models; *p<0.05", 
          notes.append = FALSE, 
          no.space=TRUE, out = "Study1_Kam.tex",dep.var.caption = "Policy support",dep.var.labels.include = F,label="tab:kam", digits=2)



### Appendix A.8: Item-by-item analyses - ITEM 1----------------
twoway_crt<-(lm(zero1(SupportIrradiation_rec)~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall+age+female+non_white+as.factor(education)+Republican_dummy,data))
twoway_nfc<-(lm(zero1(SupportIrradiation_rec)~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc+age+female+non_white+as.factor(education)+Republican_dummy,data))
twoway_cog<-(lm(zero1(SupportIrradiation_rec)~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources+age+female+non_white+as.factor(education)+Republican_dummy,data))

#replace names 2 way model
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "nfc"] <- "CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"

names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "cogresources"] <- "CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"

threeway_crt<-(lm(zero1(SupportIrradiation_rec)~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall+InParty*partyidentity*CRTall+OutParty*partyidentity*CRTall +age+female+non_white+as.factor(education)+Republican_dummy,data))
threeway_nfc<-(lm(zero1(SupportIrradiation_rec)~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc+InParty*partyidentity*nfc+OutParty*partyidentity*nfc+age+female+non_white+as.factor(education)+Republican_dummy,data))
threeway_cog<-(lm(zero1(SupportIrradiation_rec)~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources+InParty*partyidentity*cogresources+OutParty*partyidentity*cogresources+age+female+non_white+as.factor(education)+Republican_dummy,data))

#replace names 2 way model
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "nfc"] <- "CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:partyidentity:nfc"] <- "InParty:partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:partyidentity:nfc"] <- "OutParty:partyidentity:CRTall"

names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "cogresources"] <- "CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:partyidentity:cogresources"] <- "InParty:partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:partyidentity:cogresources"] <- "OutParty:partyidentity:CRTall"

stargazer(twoway_crt, threeway_crt,twoway_nfc, threeway_nfc, twoway_cog, threeway_cog, title="Food Irradiation item 1 ``Support'': Policy support, party cues, cognitive resources and social identity strength", align=TRUE,
          notes.append = FALSE, order=c(1,2,3,4, 11, 12, 13,14,15,16,17,5,6,7,8,9,10), covariate.labels=c("In-party cue", "Out-party cue", "Partisan Identity Strength (PSID)","Cognitive resource", "In-party * PSID", "Out-party * PSID", "In-party * Cognitive", "Out-party * Cognitive", "PSID * Cognitive", "In-party * PSID * Cognitive", "Out-party * PSID * Cognitive", "Age", "Female", "Race: non-white", "Education: Some college", "Education: College", "Party: Republican", "Constant"),
          star.cutoffs=c(0.05), omit.stat=c("LL","ser","f", "adj.rsq"), 
          notes = "*p<0.05", 
          column.sep.width = "1pt",
          no.space=TRUE, font.size="tiny" ,  out = "Study1_item1.tex",dep.var.caption = "Policy support",column.labels = c("CRT", "NFC", "Cog resources"), column.separate = c(2,2,2), dep.var.labels.include = FALSE,label="tab:item1", digits=2)

## CRT at 0 or -1SD
m0 <- lm(zero1(SupportIrradiation_rec)~InParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_out <- interplot(m0,var1 = "OutParty",var2='partyidentity')
m_0_out$data$CRT='-1 SD'
m_0_out$data$Cue='Out'
m_0_in <- interplot(m0,var1 = "InParty",var2='partyidentity')
m_0_in$data$CRT='-1 SD'
m_0_in$data$Cue='In'
## CRT at mean
m1 <- lm(zero1(SupportIrradiation_rec)~InParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_out <- interplot(m1,var1 = "OutParty",var2='partyidentity')
m_1_out$data$CRT='Mean'
m_1_out$data$Cue='Out'
m_1_in <- interplot(m1,var1 = "InParty",var2='partyidentity')
m_1_in$data$CRT='Mean'
m_1_in$data$Cue='In'
## CRT at +1
m2 <- lm(zero1(SupportIrradiation_rec)~InParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity+ OutParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_out <- interplot(m2,var1 = "OutParty",var2='partyidentity')
m_2_out$data$CRT='+1 SD'
m_2_out$data$Cue='Out'
m_2_in <- interplot(m2,var1 = "InParty",var2='partyidentity')
m_2_in$data$CRT='+1 SD'
m_2_in$data$Cue='In'

forplot_crt <- rbind(m_0_in$data, m_0_out$data,m_1_in$data,m_1_out$data,m_2_in$data,m_2_out$data)
forplot_crt$battery      <- c("CRT")
forplot_crt$CRT <- factor(forplot_crt$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########NFC
## NFC -1SD
m0_nfc <- lm(zero1(SupportIrradiation_rec)~InParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

## NfC at mean
m1_nfc <- lm(zero1(SupportIrradiation_rec)~InParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity+OutParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

## NfC at +1
m2_nfc <- lm(zero1(SupportIrradiation_rec)~InParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_nfc <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_nfc$battery      <- c("NFC")
forplot_nfc$CRT <- factor(forplot_nfc$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########Cog resoucres
## Cog resoucrres -1SD
m0_nfc <- lm(zero1(SupportIrradiation_rec)~InParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

##  Cog resoucrres  at mean
m1_nfc <- lm(zero1(SupportIrradiation_rec)~InParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity+OutParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

##  Cog resoucrres  at +1
m2_nfc <- lm(zero1(SupportIrradiation_rec)~InParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_cog <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_cog$battery      <- c("Cognitive\n resources")
forplot_cog$CRT <- factor(forplot_cog$CRT,levels = c("-1 SD","Mean","+1 SD"))

forplot_comb <- rbind(forplot_crt, forplot_nfc, forplot_cog)
forplot_comb$battery <- factor(forplot_comb$battery,levels = c("CRT","NFC","Cognitive\n resources"))

foodirradiation1<-ggplot(forplot_comb,aes(x=fake,y=coef1, colour=Cue))+geom_line(aes(linetype=Cue, color=Cue))+facet_grid(battery~CRT)+xlab("Partisan Social Identity Strength")+theme_bw()+ylab("Marginal effect of Party Cues on Policy Support ")+geom_ribbon(aes(ymin=lb,ymax=ub, fill=Cue),alpha=.4)+geom_hline(yintercept = 0,lty="dashed")+scale_fill_manual(values=c("dark green", "red"))+scale_colour_manual(values=c("black", "black")) + theme(strip.text.y = element_text(angle = 360), legend.position="bottom")
ggsave(foodirradiation1, file="Food_item1.pdf",width=8,height=6)

### Appendix A.8: Item-by-item analyses - ITEM 2----------------
twoway_crt<-(lm(zero1(CostsFoodIrradiation_rec)~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall+age+female+non_white+as.factor(education)+Republican_dummy,data))
twoway_nfc<-(lm(zero1(CostsFoodIrradiation_rec)~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc+age+female+non_white+as.factor(education)+Republican_dummy,data))
twoway_cog<-(lm(zero1(CostsFoodIrradiation_rec)~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources+age+female+non_white+as.factor(education)+Republican_dummy,data))

#replace names 2 way model
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "nfc"] <- "CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"

names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "cogresources"] <- "CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"

threeway_crt<-(lm(zero1(CostsFoodIrradiation_rec)~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall+InParty*partyidentity*CRTall+OutParty*partyidentity*CRTall +age+female+non_white+as.factor(education)+Republican_dummy,data))
threeway_nfc<-(lm(zero1(CostsFoodIrradiation_rec)~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc+InParty*partyidentity*nfc+OutParty*partyidentity*nfc+age+female+non_white+as.factor(education)+Republican_dummy,data))
threeway_cog<-(lm(zero1(CostsFoodIrradiation_rec)~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources+InParty*partyidentity*cogresources+OutParty*partyidentity*cogresources+age+female+non_white+as.factor(education)+Republican_dummy,data))

#replace names 2 way model
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "nfc"] <- "CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:partyidentity:nfc"] <- "InParty:partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:partyidentity:nfc"] <- "OutParty:partyidentity:CRTall"

names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "cogresources"] <- "CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:partyidentity:cogresources"] <- "InParty:partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:partyidentity:cogresources"] <- "OutParty:partyidentity:CRTall"

stargazer(twoway_crt, threeway_crt,twoway_nfc, threeway_nfc, twoway_cog, threeway_cog, title="Food Irradiation item 2 ``Cost versus Benefit'': Policy support, party cues, cognitive resources and social identity strength", align=TRUE,
          notes.append = FALSE, order=c(1,2,3,4, 11, 12, 13,14,15,16,17,5,6,7,8,9,10), covariate.labels=c("In-party cue", "Out-party cue", "Partisan Identity Strength (PSID)","Cognitive resource", "In-party * PSID", "Out-party * PSID", "In-party * Cognitive", "Out-party * Cognitive", "PSID * Cognitive", "In-party * PSID * Cognitive", "Out-party * PSID * Cognitive", "Age", "Female", "Race: non-white", "Education: Some college", "Education: College", "Party: Republican", "Constant"),
          star.cutoffs=c(0.05), omit.stat=c("LL","ser","f", "adj.rsq"), 
          notes = "*p<0.05", 
          column.sep.width = "1pt",
          no.space=TRUE, font.size="tiny" ,  out = "Study1_item2.tex",dep.var.caption = "Policy support",column.labels = c("CRT", "NFC", "Cog resources"), column.separate = c(2,2,2), dep.var.labels.include = FALSE,label="tab:item2", digits=2)

## CRT at 0 or -1SD
m0 <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_out <- interplot(m0,var1 = "OutParty",var2='partyidentity')
m_0_out$data$CRT='-1 SD'
m_0_out$data$Cue='Out'
m_0_in <- interplot(m0,var1 = "InParty",var2='partyidentity')
m_0_in$data$CRT='-1 SD'
m_0_in$data$Cue='In'
## CRT at mean
m1 <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_out <- interplot(m1,var1 = "OutParty",var2='partyidentity')
m_1_out$data$CRT='Mean'
m_1_out$data$Cue='Out'
m_1_in <- interplot(m1,var1 = "InParty",var2='partyidentity')
m_1_in$data$CRT='Mean'
m_1_in$data$Cue='In'
## CRT at +1
m2 <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity+ OutParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_out <- interplot(m2,var1 = "OutParty",var2='partyidentity')
m_2_out$data$CRT='+1 SD'
m_2_out$data$Cue='Out'
m_2_in <- interplot(m2,var1 = "InParty",var2='partyidentity')
m_2_in$data$CRT='+1 SD'
m_2_in$data$Cue='In'

forplot_crt <- rbind(m_0_in$data, m_0_out$data,m_1_in$data,m_1_out$data,m_2_in$data,m_2_out$data)
forplot_crt$battery      <- c("CRT")
forplot_crt$CRT <- factor(forplot_crt$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########NFC
## NFC -1SD
m0_nfc <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

## NfC at mean
m1_nfc <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity+OutParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

## NfC at +1
m2_nfc <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_nfc <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_nfc$battery      <- c("NFC")
forplot_nfc$CRT <- factor(forplot_nfc$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########Cog resoucres
## Cog resoucrres -1SD
m0_nfc <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

##  Cog resoucrres  at mean
m1_nfc <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity+OutParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

##  Cog resoucrres  at +1
m2_nfc <- lm(zero1(CostsFoodIrradiation_rec)~InParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_cog <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_cog$battery      <- c("Cognitive\n resources")
forplot_cog$CRT <- factor(forplot_cog$CRT,levels = c("-1 SD","Mean","+1 SD"))

forplot_comb <- rbind(forplot_crt, forplot_nfc, forplot_cog)
forplot_comb$battery <- factor(forplot_comb$battery,levels = c("CRT","NFC","Cognitive\n resources"))

foodirradiation1<-ggplot(forplot_comb,aes(x=fake,y=coef1, colour=Cue))+geom_line(aes(linetype=Cue, color=Cue))+facet_grid(battery~CRT)+xlab("Partisan Social Identity Strength")+theme_bw()+ylab("Marginal effect of Party Cues on Policy Support ")+geom_ribbon(aes(ymin=lb,ymax=ub, fill=Cue),alpha=.4)+geom_hline(yintercept = 0,lty="dashed")+scale_fill_manual(values=c("dark green", "red"))+scale_colour_manual(values=c("black", "black")) + theme(strip.text.y = element_text(angle = 360), legend.position="bottom")
ggsave(foodirradiation1, file="Food_item2.pdf",width=8,height=6)

### Appendix A.8: Item-by-item analyses - ITEM 3----------------
twoway_crt<-(lm(zero1(IrradiationGood_rec)~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall+age+female+non_white+as.factor(education)+Republican_dummy,data))
twoway_nfc<-(lm(zero1(IrradiationGood_rec)~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc+age+female+non_white+as.factor(education)+Republican_dummy,data))
twoway_cog<-(lm(zero1(IrradiationGood_rec)~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources+age+female+non_white+as.factor(education)+Republican_dummy,data))

#replace names 2 way model
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "nfc"] <- "CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"

names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "cogresources"] <- "CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"

threeway_crt<-(lm(zero1(IrradiationGood_rec)~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall+InParty*partyidentity*CRTall+OutParty*partyidentity*CRTall +age+female+non_white+as.factor(education)+Republican_dummy,data))
threeway_nfc<-(lm(zero1(IrradiationGood_rec)~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc+InParty*partyidentity*nfc+OutParty*partyidentity*nfc+age+female+non_white+as.factor(education)+Republican_dummy,data))
threeway_cog<-(lm(zero1(IrradiationGood_rec)~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources+InParty*partyidentity*cogresources+OutParty*partyidentity*cogresources+age+female+non_white+as.factor(education)+Republican_dummy,data))

#replace names 2 way model
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "nfc"] <- "CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:partyidentity:nfc"] <- "InParty:partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:partyidentity:nfc"] <- "OutParty:partyidentity:CRTall"

names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "cogresources"] <- "CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:partyidentity:cogresources"] <- "InParty:partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:partyidentity:cogresources"] <- "OutParty:partyidentity:CRTall"

stargazer(twoway_crt, threeway_crt,twoway_nfc, threeway_nfc, twoway_cog, threeway_cog, title="Food Irradiation item 3 ``Good versus Bad'': Policy support, party cues, cognitive resources and social identity strength", align=TRUE,
          notes.append = FALSE, order=c(1,2,3,4, 11, 12, 13,14,15,16,17,5,6,7,8,9,10), covariate.labels=c("In-party cue", "Out-party cue", "Partisan Identity Strength (PSID)","Cognitive resource", "In-party * PSID", "Out-party * PSID", "In-party * Cognitive", "Out-party * Cognitive", "PSID * Cognitive", "In-party * PSID * Cognitive", "Out-party * PSID * Cognitive", "Age", "Female", "Race: non-white", "Education: Some college", "Education: College", "Party: Republican", "Constant"),
          star.cutoffs=c(0.05), omit.stat=c("LL","ser","f", "adj.rsq"), 
          notes = "*p<0.05", 
          column.sep.width = "1pt",
          no.space=TRUE, font.size="tiny" ,  out = "Study1_item3.tex",dep.var.caption = "Policy support",column.labels = c("CRT", "NFC", "Cog resources"), column.separate = c(2,2,2), dep.var.labels.include = FALSE,label="tab:item3", digits=2)

## CRT at 0 or -1SD
m0 <- lm(zero1(IrradiationGood_rec)~InParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_out <- interplot(m0,var1 = "OutParty",var2='partyidentity')
m_0_out$data$CRT='-1 SD'
m_0_out$data$Cue='Out'
m_0_in <- interplot(m0,var1 = "InParty",var2='partyidentity')
m_0_in$data$CRT='-1 SD'
m_0_in$data$Cue='In'
## CRT at mean
m1 <- lm(zero1(IrradiationGood_rec)~InParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_out <- interplot(m1,var1 = "OutParty",var2='partyidentity')
m_1_out$data$CRT='Mean'
m_1_out$data$Cue='Out'
m_1_in <- interplot(m1,var1 = "InParty",var2='partyidentity')
m_1_in$data$CRT='Mean'
m_1_in$data$Cue='In'
## CRT at +1
m2 <- lm(zero1(IrradiationGood_rec)~InParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity+ OutParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_out <- interplot(m2,var1 = "OutParty",var2='partyidentity')
m_2_out$data$CRT='+1 SD'
m_2_out$data$Cue='Out'
m_2_in <- interplot(m2,var1 = "InParty",var2='partyidentity')
m_2_in$data$CRT='+1 SD'
m_2_in$data$Cue='In'

forplot_crt <- rbind(m_0_in$data, m_0_out$data,m_1_in$data,m_1_out$data,m_2_in$data,m_2_out$data)
forplot_crt$battery      <- c("CRT")
forplot_crt$CRT <- factor(forplot_crt$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########NFC
## NFC -1SD
m0_nfc <- lm(zero1(IrradiationGood_rec)~InParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

## NfC at mean
m1_nfc <- lm(zero1(IrradiationGood_rec)~InParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity+OutParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

## NfC at +1
m2_nfc <- lm(zero1(IrradiationGood_rec)~InParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_nfc <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_nfc$battery      <- c("NFC")
forplot_nfc$CRT <- factor(forplot_nfc$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########Cog resoucres
## Cog resoucrres -1SD
m0_nfc <- lm(zero1(IrradiationGood_rec)~InParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

##  Cog resoucrres  at mean
m1_nfc <- lm(zero1(IrradiationGood_rec)~InParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity+OutParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

##  Cog resoucrres  at +1
m2_nfc <- lm(zero1(IrradiationGood_rec)~InParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_cog <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_cog$battery      <- c("Cognitive\n resources")
forplot_cog$CRT <- factor(forplot_cog$CRT,levels = c("-1 SD","Mean","+1 SD"))

forplot_comb <- rbind(forplot_crt, forplot_nfc, forplot_cog)
forplot_comb$battery <- factor(forplot_comb$battery,levels = c("CRT","NFC","Cognitive\n resources"))

foodirradiation1<-ggplot(forplot_comb,aes(x=fake,y=coef1, colour=Cue))+geom_line(aes(linetype=Cue, color=Cue))+facet_grid(battery~CRT)+xlab("Partisan Social Identity Strength")+theme_bw()+ylab("Marginal effect of Party Cues on Policy Support ")+geom_ribbon(aes(ymin=lb,ymax=ub, fill=Cue),alpha=.4)+geom_hline(yintercept = 0,lty="dashed")+scale_fill_manual(values=c("dark green", "red"))+scale_colour_manual(values=c("black", "black")) + theme(strip.text.y = element_text(angle = 360), legend.position="bottom")
ggsave(foodirradiation1, file="Food_item3.pdf",width=8,height=6)




### Appendix A.9: Inspection of non-linearity----------------------------

#create categorical variable
data$partyidentity_cats1<-NA
data$partyidentity_cats1[data$partyidentity<.333]=0
data$partyidentity_cats1[data$partyidentity>.333 & data$partyidentity<.542]=1
data$partyidentity_cats1[data$partyidentity>=.542]=2
data$partyidentity_cats1 <- factor(data$partyidentity_cats1,levels = c(0,1,2), label=c("low", "modest", "high"))

## CRT at 0 or -1SD
m0 <- lm(DV_irradiation~InParty*scale(CRTall,center=0,scale=F)*partyidentity_cats1+OutParty*scale(CRTall,center=0,scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_out <- interplot(m0,var1 = "OutParty",var2='partyidentity_cats1')
m_0_out$data$CRT='-1 SD'
m_0_out$data$Cue='Out'
m_0_in <- interplot(m0,var1 = "InParty",var2='partyidentity_cats1')
m_0_in$data$CRT='-1 SD'
m_0_in$data$Cue='In'

## CRT at mean
m1 <- lm(DV_irradiation~InParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity_cats1+OutParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_out <- interplot(m1,var1 = "OutParty",var2='partyidentity_cats1')
m_1_out$data$CRT='Mean'
m_1_out$data$Cue='Out'
m_1_in <- interplot(m1,var1 = "InParty",var2='partyidentity_cats1')
m_1_in$data$CRT='Mean'
m_1_in$data$Cue='In'
## CRT at +1
m2 <- lm(DV_irradiation~InParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity_cats1+ OutParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m2)
m_2_out <- interplot(m2,var1 = "OutParty",var2='partyidentity_cats1')
m_2_out$data$CRT='+1 SD'
m_2_out$data$Cue='Out'
m_2_in <- interplot(m2,var1 = "InParty",var2='partyidentity_cats1')
m_2_in$data$CRT='+1 SD'
m_2_in$data$Cue='In'

forplot <- rbind(m_0_in$data, m_0_out$data,m_1_in$data,m_1_out$data,m_2_in$data,m_2_out$data)
forplot$battery      <- c("CRT")
forplot$CRT <- factor(forplot$CRT,levels = c("-1 SD","Mean","+1 SD"))

#remove lines that are not necessary
forplot <- forplot[-c(3, 7,11,15,19,23), ] 
forplot$fake<-rep(1:3,6)
forplot$fake <- factor(forplot$fake,levels = c("1","2","3"))

#NFC
## NFC -1SD
m0_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity_cats1+ OutParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity_cats1')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity_cats1')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

## NfC at mean
m1_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity_cats1+OutParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity_cats1')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity_cats1')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

## NfC at +1
m2_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity_cats1+ OutParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity_cats1')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity_cats1')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_nfc <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_nfc$battery      <- c("NFC")

#remove lines that are not necessary
forplot_nfc <- forplot_nfc[-c(3, 7,11,15,19,23), ] 
forplot_nfc$fake<-rep(1:3,6)
forplot_nfc$fake <- factor(forplot_nfc$fake,levels = c("1","2","3"))
forplot_nfc$CRT <- factor(forplot$CRT,levels = c("-1 SD","Mean","+1 SD"))

#Cog resources
## NFC -1SD
m0_nfc <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity_cats1+ OutParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity_cats1')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity_cats1')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

## NfC at mean
m1_nfc <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity_cats1+OutParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity_cats1')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity_cats1')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

## NfC at +1
m2_nfc <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity_cats1+ OutParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity_cats1+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity_cats1')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity_cats1')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_cog <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_cog$battery      <- c("Cognitive\n resources")

#remove lines that are not necessary
forplot_cog <- forplot_cog[-c(3, 7,11,15,19,23), ] 
forplot_cog$fake<-rep(1:3,6)
forplot_cog$fake <- factor(forplot_cog$fake,levels = c("1","2","3"))
forplot_cog$CRT <- factor(forplot_cog$CRT,levels = c("-1 SD","Mean","+1 SD"))

forplot_comb <- rbind(forplot, forplot_nfc, forplot_cog)
forplot_comb$battery<-factor(forplot_comb$battery,levels = c("CRT","NFC","Cognitive\n resources"))

ggplot(forplot_comb,aes(x=fake,y=coef1, colour=Cue))+facet_grid(battery~CRT)+xlab("Partisan Social Identity Strength")+theme_bw()+ylab("Marginal effect of In-party Cue on Policy Support ")+geom_pointrange(aes(ymin=lb,ymax=ub, fill=Cue),alpha=1, position=position_dodge(width=0.2))+geom_hline(yintercept = 0,lty="dashed")+scale_colour_manual(values = c("dark green", "red")) +scale_x_discrete(labels = c("1" = "Weak","2" = "Modest", "3"="Strong"))+ theme(strip.text.y = element_text(angle = 360), legend.position="bottom")
ggsave("Study1_Food_nonlinear.pdf",width=8,height=6)




### Appendix F: Traditional measure of partisanship strength-------------------------
cor.test(data$pidstrength, data$partyidentity)

## CRT at 0 or -1SD
m0 <- lm(DV_irradiation~InParty*scale(CRTall,center=0,scale=F)*pidstrength+OutParty*scale(CRTall,center=0,scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
m_0_out <- interplot(m0,var1 = "OutParty",var2='pidstrength')
m_0_out$data$CRT='-1 SD'
m_0_out$data$Cue='Out'
m_0_in <- interplot(m0,var1 = "InParty",var2='pidstrength')
m_0_in$data$CRT='-1 SD'
m_0_in$data$Cue='In'

## CRT at mean
m1 <- lm(DV_irradiation~InParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*pidstrength+OutParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m1)
m_1_out <- interplot(m1,var1 = "OutParty",var2='pidstrength')
m_1_out$data$CRT='Mean'
m_1_out$data$Cue='Out'
m_1_in <- interplot(m1,var1 = "InParty",var2='pidstrength')
m_1_in$data$CRT='Mean'
m_1_in$data$Cue='In'
## CRT at +1
m2 <- lm(DV_irradiation~InParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*pidstrength+ OutParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m2)
m_2_out <- interplot(m2,var1 = "OutParty",var2='pidstrength')
m_2_out$data$CRT='+1 SD'
m_2_out$data$Cue='Out'
m_2_in <- interplot(m2,var1 = "InParty",var2='pidstrength')
m_2_in$data$CRT='+1 SD'
m_2_in$data$Cue='In'

forplot <- rbind(m_0_in$data, m_0_out$data,m_1_in$data,m_1_out$data,m_2_in$data,m_2_out$data)
forplot$battery      <- c("CRT")
forplot$CRT <- factor(forplot$CRT,levels = c("-1 SD","Mean","+1 SD"))

## NFC -1SD
m0_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*pidstrength+ OutParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m0_nfc)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='pidstrength')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='pidstrength')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'


## NfC at mean
m1_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*pidstrength+OutParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m1_nfc)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='pidstrength')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='pidstrength')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

## NfC at +1
m2_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*pidstrength+ OutParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m2_nfc)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='pidstrength')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='pidstrength')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_nfc <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_nfc$battery      <- c("NFC")
forplot_nfc$CRT <- factor(forplot$CRT,levels = c("-1 SD","Mean","+1 SD"))

## NFC -1SD
m0_cogresources <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*pidstrength+ OutParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m0_cogresources)
m_0_in_cogresources <- interplot(m0_cogresources,var1 = "InParty",var2='pidstrength')
m_0_in_cogresources$data$CRT='-1 SD'
m_0_in_cogresources$data$Cue='In'
m_0_out_cogresources <- interplot(m0_cogresources,var1 = "OutParty",var2='pidstrength')
m_0_out_cogresources$data$CRT='-1 SD'
m_0_out_cogresources$data$Cue='Out'

## cogresources at mean
m1_cogresources <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*pidstrength+OutParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m1_cogresources)
m_1_in_cogresources <- interplot(m1_cogresources,var1 = "InParty",var2='pidstrength')
m_1_in_cogresources$data$CRT='Mean'
m_1_in_cogresources$data$Cue='In'
m_1_out_cogresources <- interplot(m1_cogresources,var1 = "OutParty",var2='pidstrength')
m_1_out_cogresources$data$CRT='Mean'
m_1_out_cogresources$data$Cue='Out'

## cogresources at +1
m2_cogresources <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*pidstrength+ OutParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*pidstrength+age+female+non_white+as.factor(education)+Republican_dummy,data)
summary(m2_cogresources)
m_2_in_cogresources <- interplot(m2_cogresources,var1 = "InParty",var2='pidstrength')
m_2_in_cogresources$data$CRT='+1 SD'
m_2_in_cogresources$data$Cue='In'
m_2_out_cogresources <- interplot(m2_cogresources,var1 = "OutParty",var2='pidstrength')
m_2_out_cogresources$data$CRT='+1 SD'
m_2_out_cogresources$data$Cue='Out'

forplot_cogresources <- rbind(m_0_in_cogresources$data, m_0_out_cogresources$data,m_1_in_cogresources$data,m_1_out_cogresources$data,m_2_in_cogresources$data,m_2_out_cogresources$data)
forplot_cogresources$battery      <- c("Cognitive\n resources")
forplot_cogresources$CRT <- factor(forplot_cogresources$CRT,levels = c("-1 SD","Mean","+1 SD"))
forplot_comb <- rbind(forplot, forplot_nfc, forplot_cogresources)

forplot_comb$battery <- factor(forplot_comb$battery,levels = c("CRT","NFC", "Cognitive\n resources"))
ggplot(forplot_comb,aes(x=fake,y=coef1, colour=Cue))+facet_grid(battery~CRT)+xlab("Party Identity Strength")+theme_bw()+ylab("Marginal effect of In-party cue and Out-party cue on Policy Support ")+geom_pointrange(aes(ymin=lb,ymax=ub, fill=Cue),alpha=1, position=position_dodge(width=0.2))+geom_hline(yintercept = 0,lty="dashed")+scale_colour_manual(values = c("dark green", "red"))+scale_x_discrete(labels = c("1" = "Not","2" = "Weak", "3"="Strong"))+ theme(strip.text.y = element_text(angle = 360), legend.position="bottom")

ggsave("Study1_Food_pidstrenght.pdf",width=8,height=6)



### Appendix G: Ideological signalling-------------------------

appendix_g<-list()
summary(appendix_g[[1]]<-lm(DV_irradiation~partisanship_ind,subset(data, Treatment==1)))
summary(appendix_g[[2]]<-lm(DV_irradiation~Republican_dummy,subset(data, Treatment==1)))

stargazer(appendix_g[[1]], appendix_g[[2]], title="Study 1 Food Irradiation: Partisanship and policy preferences in the Control Condition (no-Cues", align=TRUE,  notes.append = FALSE, covariate.labels=c("Partisanship (6-point)", "Republican (Ref. Democrat)"), star.cutoffs=c(0.05), omit.stat=c("LL","ser","f", "adj.rsq"), notes = "*p<0.05", column.sep.width = "1pt", no.space=TRUE,  out = "Study1_FoodPartisan.tex",dep.var.caption = "Policy support", dep.var.labels.include = FALSE,label="tab:partisan2", digits=2)

### Appendix: based upon footnote - models without covariates----------------
twoway_crt<-(lm(DV_irradiation~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall,data))
twoway_nfc<-(lm(DV_irradiation~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc,data))
twoway_cog<-(lm(DV_irradiation~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources,data))

#replace names 2 way model
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "nfc"] <- "CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(twoway_nfc$coefficients)[names(twoway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"

names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "cogresources"] <- "CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(twoway_cog$coefficients)[names(twoway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"

threeway_crt<-(lm(DV_irradiation~InParty+OutParty+partyidentity+CRTall+InParty*partyidentity+OutParty*partyidentity+InParty*CRTall+OutParty*CRTall+partyidentity*CRTall+InParty*partyidentity*CRTall+OutParty*partyidentity*CRTall,data))
threeway_nfc<-(lm(DV_irradiation~InParty+OutParty+partyidentity+nfc+InParty*partyidentity+OutParty*partyidentity+InParty*nfc+OutParty*nfc+partyidentity*nfc+InParty*partyidentity*nfc+OutParty*partyidentity*nfc,data))
threeway_cog<-(lm(DV_irradiation~InParty+OutParty+partyidentity+cogresources+InParty*partyidentity+OutParty*partyidentity+InParty*cogresources+OutParty*cogresources+partyidentity*cogresources+InParty*partyidentity*cogresources+OutParty*partyidentity*cogresources,data))

#replace names 3 way model
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "nfc"] <- "CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:nfc"] <- "InParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:nfc"] <- "OutParty:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "partyidentity:nfc"] <- "partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "InParty:partyidentity:nfc"] <- "InParty:partyidentity:CRTall"
names(threeway_nfc$coefficients)[names(threeway_nfc$coefficients) == "OutParty:partyidentity:nfc"] <- "OutParty:partyidentity:CRTall"

names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "cogresources"] <- "CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:cogresources"] <- "InParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:cogresources"] <- "OutParty:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "partyidentity:cogresources"] <- "partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "InParty:partyidentity:cogresources"] <- "InParty:partyidentity:CRTall"
names(threeway_cog$coefficients)[names(threeway_cog$coefficients) == "OutParty:partyidentity:cogresources"] <- "OutParty:partyidentity:CRTall"

stargazer(twoway_crt, threeway_crt,twoway_nfc, threeway_nfc, twoway_cog, threeway_cog, title="Food Irradiation: Policy support, party cues, cognitive resources and social identity strength", align=TRUE,  notes.append = FALSE, covariate.labels=c("In-party cue", "Out-party cue", "Partisan Identity Strength (PSID)","Cognitive resource", "In-party * PSID", "Out-party * PSID", "In-party * Cognitive", "Out-party * Cognitive", "PSID * Cognitive", "In-party * PSID * Cognitive", "Out-party * PSID * Cognitive", "Constant"), star.cutoffs=c(0.05), omit.stat=c("LL","ser","f", "adj.rsq"), notes = "*p<0.05", column.sep.width = "1pt", no.space=TRUE, font.size="tiny" ,dep.var.caption = "Policy support",column.labels = c("CRT", "NfC", "Cog resources"), column.separate = c(2,2,2), dep.var.labels.include = FALSE,label="tab:stud2", digits=2)


## CRT at 0 or -1SD
m0 <- lm(DV_irradiation~InParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall)-sd(CRTall),scale=F)*partyidentity,data)
summary(m0)
m_0_out <- interplot(m0,var1 = "OutParty",var2='partyidentity')
m_0_out$data$CRT='-1 SD'
m_0_out$data$Cue='Out'
m_0_in <- interplot(m0,var1 = "InParty",var2='partyidentity')
m_0_in$data$CRT='-1 SD'
m_0_in$data$Cue='In'
## CRT at mean
m1 <- lm(DV_irradiation~InParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity+OutParty*scale(CRTall,center=mean(CRTall,na.rm=T),scale=F)*partyidentity,data)
summary(m1)
m_1_out <- interplot(m1,var1 = "OutParty",var2='partyidentity')
m_1_out$data$CRT='Mean'
m_1_out$data$Cue='Out'
m_1_in <- interplot(m1,var1 = "InParty",var2='partyidentity')
m_1_in$data$CRT='Mean'
m_1_in$data$Cue='In'
## CRT at +1
m2 <- lm(DV_irradiation~InParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity+ OutParty*scale(CRTall,center=mean(CRTall)+sd(CRTall),scale=F)*partyidentity,data)
m_2_out <- interplot(m2,var1 = "OutParty",var2='partyidentity')
summary(m2)
m_2_out$data$CRT='+1 SD'
m_2_out$data$Cue='Out'
m_2_in <- interplot(m2,var1 = "InParty",var2='partyidentity')
m_2_in$data$CRT='+1 SD'
m_2_in$data$Cue='In'

forplot_crt <- rbind(m_0_in$data, m_0_out$data,m_1_in$data,m_1_out$data,m_2_in$data,m_2_out$data)
forplot_crt$battery      <- c("CRT")
forplot_crt$CRT <- factor(forplot_crt$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########NFC
## NFC -1SD
m0_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)-sd(nfc),scale=F)*partyidentity,data)
summary(m0_nfc)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

## NfC at mean
m1_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity+OutParty*scale(nfc,center=mean(nfc,na.rm=T),scale=F)*partyidentity,data)
summary(m1_nfc)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

## NfC at +1
m2_nfc <- lm(DV_irradiation~InParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity+ OutParty*scale(nfc,center=mean(nfc)+sd(nfc),scale=F)*partyidentity,data)
summary(m2_nfc)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_nfc <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_nfc$battery      <- c("NfC")
forplot_nfc$CRT <- factor(forplot_nfc$CRT,levels = c("-1 SD","Mean","+1 SD"))

##########Cog resoucres
## Cog resoucrres -1SD
m0_nfc <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)-sd(cogresources),scale=F)*partyidentity,data)
m_0_in_nfc <- interplot(m0_nfc,var1 = "InParty",var2='partyidentity')
m_0_in_nfc$data$CRT='-1 SD'
m_0_in_nfc$data$Cue='In'
m_0_out_nfc <- interplot(m0_nfc,var1 = "OutParty",var2='partyidentity')
m_0_out_nfc$data$CRT='-1 SD'
m_0_out_nfc$data$Cue='Out'

##  Cog resoucrres  at mean
m1_nfc <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity+OutParty*scale(cogresources,center=mean(cogresources,na.rm=T),scale=F)*partyidentity,data)
m_1_in_nfc <- interplot(m1_nfc,var1 = "InParty",var2='partyidentity')
m_1_in_nfc$data$CRT='Mean'
m_1_in_nfc$data$Cue='In'
m_1_out_nfc <- interplot(m1_nfc,var1 = "OutParty",var2='partyidentity')
m_1_out_nfc$data$CRT='Mean'
m_1_out_nfc$data$Cue='Out'

##  Cog resoucrres  at +1
m2_nfc <- lm(DV_irradiation~InParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity+ OutParty*scale(cogresources,center=mean(cogresources)+sd(cogresources),scale=F)*partyidentity,data)
m_2_in_nfc <- interplot(m2_nfc,var1 = "InParty",var2='partyidentity')
m_2_in_nfc$data$CRT='+1 SD'
m_2_in_nfc$data$Cue='In'
m_2_out_nfc <- interplot(m2_nfc,var1 = "OutParty",var2='partyidentity')
m_2_out_nfc$data$CRT='+1 SD'
m_2_out_nfc$data$Cue='Out'

forplot_cog <- rbind(m_0_in_nfc$data, m_0_out_nfc$data,m_1_in_nfc$data,m_1_out_nfc$data,m_2_in_nfc$data,m_2_out_nfc$data)
forplot_cog$battery      <- c("Cognitive\n resources")
forplot_cog$CRT <- factor(forplot_cog$CRT,levels = c("-1 SD","Mean","+1 SD"))

forplot_comb <- rbind(forplot_crt, forplot_nfc, forplot_cog)
forplot_comb$battery <- factor(forplot_comb$battery,levels = c("CRT","NfC","Cognitive\n resources"))

foodirradiation_no_covariates<-ggplot(forplot_comb,aes(x=fake,y=coef1, colour=Cue))+geom_line(aes(linetype=Cue, color=Cue))+facet_grid(battery~CRT)+xlab("Partisan Social Identity Strength")+theme_bw()+ylab("Marginal effect of Party Cues on Policy Support ")+geom_ribbon(aes(ymin=lb,ymax=ub, fill=Cue),alpha=.4)+geom_hline(yintercept = 0,lty="dashed")+scale_fill_manual(values=c("dark green", "red"))+scale_colour_manual(values=c("black", "black")) + theme(strip.text.y = element_text(angle = 360), legend.position="bottom")
